package com.mall.user.service.impl;

import com.mall.user.model.Cities;
import com.mall.user.mapper.CitiesMapper;
import com.mall.user.service.ICitiesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 城市表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@Service
public class CitiesServiceImpl extends ServiceImpl<CitiesMapper, Cities> implements ICitiesService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addCities(Cities cities){
        return super.save(cities);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String cityid){
        return super.removeById(cityid);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateCities(Cities cities){
        return super.updateById(cities);
    }

    @Override
    public Cities getById(String cityid){
        return super.getById(cityid);
    }

    @Override
    public List<Cities> selectList(Cities cities){
        return super.list(getQueryWrapper(cities));
    }

    @Override
    public Page<Cities> selectPage(Page<Cities> page, Cities cities){
        return super.page(page, getQueryWrapper(cities));
    }

    public LambdaQueryWrapper<Cities> getQueryWrapper(Cities cities){
        return Wrappers.<Cities>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(cities.getCityid()), Cities::getCityid, cities.getCityid())
            .eq(ObjectUtils.isNotEmpty(cities.getCity()), Cities::getCity, cities.getCity())
            .eq(ObjectUtils.isNotEmpty(cities.getProvinceid()), Cities::getProvinceid, cities.getProvinceid())
        ;
    }
}
